// pages/enterprise/binding/binding.js
import {
    ajaxPost,
    showToast
} from '../../../utils/util'
Page({

    /**
     * 页面的初始数据
     */
    data: {
        name: '',
        fullName: '',
        abbreviation: '',

    },
    changeInput(e) {
        let val = e.detail.value,
            type = e.currentTarget.dataset.type
        this.setData({
            [type]: val
        })

    },
    click() {
        let {
            name,
            fullName,
            abbreviation
        } = this.data
        if (!name) {
            showToast('error', '请输入真实姓名');
            return;
        }
        if (!fullName) {
            showToast('error', '请输入公司全称');
            return;
        }
        if (!abbreviation) {
            showToast('error', '请输入公司简称');
            return;
        }
        let data = {
            token: wx.getStorageSync('token'),
            realname: name,
            company_name: fullName,
            short_name: abbreviation,
        }
        ajaxPost('/company/setuserinfo', data, (res) => {
            if (res.code == 0) {
                if (this.data.shareType == 'code') {
                    console.log(123123);
                    wx.redirectTo({
                        url: `/pages/enterprise/listCont/listCont?id=${this.data.shareId}&type=code`
                    });
                    return;
                }
                if (this.data.shareType == 'resume') {
                    wx.redirectTo({
                        url: `/pages/enterprise/listCont/listCont?id=${this.data.shareId}&type=resume`
                    });
                    return;
                }
                wx.showToast({
                    title: '提交成功',
                    icon: 'success',
                    duration: 1500,
                    success: () => {
                        setTimeout(() => {
                            wx.redirectTo({
                                url: '../home/home',
                            })
                        }, 1500);
                    }
                });

            } else {
                showToast('text', res.msg);
            }

        })
    },
    switchover() {
        let data = {
            token: wx.getStorageSync("token"),
            usertype: 3,
        }
        ajaxPost("/authuser/usertype", data, function (res) {
            if (res.code == 0) {
                wx.redirectTo({
                    url: "/pages/student/home/home"
                });
            } else {
                showToast('text', res.msg);
            }
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (options.type == 'code' || options.type == 'resume') {
            this.setData({
                shareType: options.type,
                shareId: options.shareId
            })
        }
    },

})